const express = require('express');
const router = express.Router();

router.get('/', (req, res) => { 
    const content = [];
    for(let i = 0; i < 100; i++)
        content.push({
            id: `id${i}`,
            dealerCode: `dealerCode${i}`,
            code: 'code1',
            partOrderTypeName: 'partOrderTypeName',
            transportType: 1,
            submitTime: '2019-02-06',
            status: 1,
            totalAmount: 1105464,
            amountMeetFullRate: 0.1,
            totalAmountFullRate: 1313.312,
            partInvoiceCode: '120',
            deliverInvoiceCode: 'deliverInvoiceCode',
            delivedDate: '2019-07-01',
            currency: 1,
            rowVersion: 'rowVersion',
            options: [
                'deliver',
                'close',
                'backOrder',
                'detail'
            ]
        });
    res.json({
        message: '',
        payload: {
            content,
            totalElements: 100,
        }
    });
});

router.get('/:id', async(req, res, next) => {
    res.json({
        message: '',
        payload: {
            id: '001',
            rowVersion: 'string',
            partInvoices: [
                {
                    partInvoiceCode: 'partInvoiceCode001',
                    itemCount: 15,
                    totalAmount: 250000.00,
                    amountMeetRate: 0.20,
                    quantityMeetRate: 0.80,
                    partInvoiceId: '1',
                    shipmentDay: 10,
                    amountMeetFullRate: 0.25,
                    deliverInvoiceCode: 'deliverInvoiceCode',
                    fullRateAbnormal: false,
                    deliveryAbnormal: true,
                    isDefault: true
                },
                {
                    partInvoiceCode: 'partInvoiceCode002',
                    itemCount: 20,
                    totalAmount: 210000.00,
                    amountMeetRate: 0.30,
                    quantityMeetRate: 0.40,
                    partInvoiceId: '2',
                    shipmentDay: 10,
                    amountMeetFullRate: 0.25,
                    fullRateAbnormal: false,
                    deliveryAbnormal: false,
                    isDefault: false
                },
                {
                    partInvoiceCode: 'partInvoiceCode003',
                    itemCount: 30,
                    totalAmount: 12000,
                    amountMeetRate: 0.20,
                    quantityMeetRate: 0.60,
                    partInvoiceId: '3',
                    shipmentDay: 10,
                    amountMeetFullRate: 0.25,
                    fullRateAbnormal: true,
                    deliveryAbnormal: false,
                    isDefault: false
                }
            ]
        }
    });
});

router.put('/:id/close', (req, res) => {
    res.json(
        {
            message: '关闭成功'
        }
    );
});

router.put('/:id/deliver', (req, res) => {
    res.json(
        {
            message: '交付成功'
        }
    );
});

router.get('/:id/backorder', async(req, res, next) => {
    res.json({
        message: '',
        payload: {
            partInvoiceId: '001',
            code: 'code001',
            partSaleOrderCode: 'partSaleOrderCode001',
            oldPartCode: 'oldPartCode',
            totalQuantity: '1125',
            quantity: '100',
            rowVersion: 'string',
        }
    });
});
router.get('/:id/detail', async(req, res, next) => {
    res.json({
        message: '',
        payload: {
            id: '001',
            fullRateAbnormal: false,
            deliveryAbnormal: true,
            amountMeetFullRate: 0.25,
            noRateReason: 'noRateReason-string',
            noTimeSubjectiveReason: 'noTimeSubjectiveReason-string',
            noTimeObjectiveReason: 'noTimeObjectiveReason-string',
            partInvoices: [
                {
                    partInvoiceCode: 'partInvoiceCode001',
                    itemCount: 15,
                    totalAmount: 250000.00,
                    amountMeetFullRate: 0.20,
                    quantityMeetFullRate: 0.80,
                    partInvoiceId: '1',
                    shipmentDay: 10,
                    isDefault: true
                },
                {
                    partInvoiceCode: 'partInvoiceCode002',
                    itemCount: 20,
                    totalAmount: 210000.00,
                    amountMeetFullRate: 0.30,
                    quantityMeetFullRate: 0.40,
                    partInvoiceId: '2',
                    shipmentDay: 10,
                    isDefault: false
                },
                {
                    partInvoiceCode: 'partInvoiceCode003',
                    itemCount: 30,
                    totalAmount: 12000,
                    amountMeetFullRate: 0.20,
                    quantityMeetFullRate: 0.60,
                    partInvoiceId: '3',
                    shipmentDay: 10,
                    isDefault: false
                }
            ]
        }
    });
});
module.exports = router;
